package com.gollum.config;

import com.gollum.config.properties.SwaggerProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * <p>
 * swagger 配置
 * </p>
 *
 * @author Herther
 * @version 1.0.0
 * @createTime 2022年08月23日 22:58:00
 */
@SuppressWarnings("ALL")
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {


    @Autowired
    protected SwaggerProperties swaggerProperties;

    @Bean
    public Docket docket() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(swaggerProperties.getTitle())
                        .description(swaggerProperties.getDescription())
                        .termsOfServiceUrl(swaggerProperties.getLicenseUrl())
                        .version(swaggerProperties.getVersion())
                        .contact(swaggerProperties.getContact())
                        .build())
                //分组名称
                .groupName(swaggerProperties.getTitle() + ": " +swaggerProperties.getVersion() + "版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.gollum.web.controller"))
                .paths(PathSelectors.any())
                .build();
        docket.enable(swaggerProperties.getEnabled());
        return docket;
    }


}
